fix(tests): stabilize webkit keyboard handler tests with programmatic cursor positioning#2746
Conversation
… cursor positioning ArrowUp in WebKit (especially Linux) can position the cursor incorrectly when crossing blocks with different indentation levels, causing Delete/ Backspace tests to fail intermittently. Replace unreliable keyboard navigation (ArrowUp, Control+ArrowLeft, ControlOrMeta+ArrowLeft/Right) with programmatic cursor positioning via BlockNote's setTextCursorPosition API.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR adds two new Playwright test utilities that programmatically position the cursor at the start or end of the current block in BlockNote, then updates six keyboard handler end-to-end tests to use these helpers instead of keyboard shortcut sequences for cursor navigation before testing backspace and delete behaviors. ChangesTest Helper Utilities
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts (1)
241-254:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd
moveCursorToBlockEndto stabilize these Delete tests for WebKit.Three tests use
ArrowUpafter creating nested blocks withTab, then immediately invokeDelete. The WebKit issue (cursor positioning when crossing indentation levels) affects these exact patterns, yet they weren't updated with cursor helpers in the same commit that fixed similar tests:
- "Check Delete end of block with inline content child" (line 250)
- "Check Delete end of block with image child" (line 263)
- "Check Delete end of block with table child" (line 275)
Compare with nearby tests added in the same commit (
deleteMultipleChildren,deleteNestedChildren,deleteShallowerBlock) which all useawait moveCursorToBlockEnd(page);beforeDelete. Apply the same pattern here to match the established fix and prevent intermittent WebKit failures.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts` around lines 241 - 254, The three failing tests ("Check Delete end of block with inline content child", "Check Delete end of block with image child", "Check Delete end of block with table child") perform ArrowUp then Delete and need stabilization for WebKit: insert await moveCursorToBlockEnd(page); after the ArrowUp keypress (and before page.keyboard.press("Delete")) in each test so the cursor is reliably placed at the block end; keep the rest of the flow (Tab, insertParagraph, ArrowUp, Delete, compareDocToSnapshot) unchanged and reference the helper moveCursorToBlockEnd(page) used by nearby tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts`:
- Around line 241-254: The three failing tests ("Check Delete end of block with
inline content child", "Check Delete end of block with image child", "Check
Delete end of block with table child") perform ArrowUp then Delete and need
stabilization for WebKit: insert await moveCursorToBlockEnd(page); after the
ArrowUp keypress (and before page.keyboard.press("Delete")) in each test so the
cursor is reliably placed at the block end; keep the rest of the flow (Tab,
insertParagraph, ArrowUp, Delete, compareDocToSnapshot) unchanged and reference
the helper moveCursorToBlockEnd(page) used by nearby tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a489c3b3-8f65-47be-aa93-3ee64e9739a0
📒 Files selected for processing (2)
tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.tstests/src/utils/editor.ts
Summary
Fixes flaky WebKit Playwright test failures in keyboard handler tests (
keyboardhandlers.test.ts). These tests were failing intermittently on Linux WebKit CI but never on Chromium or Firefox.Root Cause
When
ArrowUpnavigates the cursor between blocks at different indentation levels, the browser maps the visual X coordinate from the source line into the target line. If the target block is more indented (starts further right), the end-of-text X from a shallower block falls mid-text in the deeper block, causing the cursor to land before the end of the line.This is correct browser behavior (ArrowUp preserves visual X position), not a bug. The cursor position is also slightly non-deterministic due to sub-pixel rendering, varying by 1 character position between runs.
Why only some tests are affected
Why only WebKit on Linux CI
Tested all 3 browsers on macOS -- both Chromium and WebKit land mid-text in the affected cases (Firefox always clamps to line end). Linux Chromium appears to handle this differently (always landing at line end), which is why only Linux WebKit exhibited the flakiness.
Why not use keyboard shortcuts (End, Meta+Arrow) instead?
Tested across all 3 browsers:
Endkey: doesn't work in WebKit (cursor stays put)Homekey: doesn't work in Firefox or WebKitMeta+ArrowRight/Left: works on macOS but maps toCtrl+Arrowon Linux (word jump, not line end)No single keyboard shortcut reliably moves to line start/end across all browsers and platforms.
Fix
Added two helper functions in
tests/src/utils/editor.ts:moveCursorToBlockEnd(page)-- programmatically sets cursor to end of current block via BlockNote APImoveCursorToBlockStart(page)-- programmatically sets cursor to start of current block via BlockNote APIThese use
editor.setTextCursorPosition(block, "end"/"start")which is deterministic and browser-independent. Applied to the 6 tests that navigate across different indentation levels before pressing Delete/Backspace.Tests modified
moveCursorToBlockStartmoveCursorToBlockStartmoveCursorToBlockEndmoveCursorToBlockEndmoveCursorToBlockEndmoveCursorToBlockEnd